	function Redirect(site)
{
	window.location = site;
}

function GetTime()
{
	var varDate = new Date();
	var varOutput = varDate.getDate() + "." + (varDate.getMonth() + 1)+"."+varDate.getFullYear();
	varOutput = varOutput + " " + (varDate.getHours() + 1) + ":" + (varDate.getMinutes() + 1);
	
	document.getElementById("time").innerHTML = varOutput;
}

function InsertDate(varTarget)
{
	var varDate = new Date();
	var varOutput = varDate.getDate() + "." + (varDate.getMonth() + 1)+"."+varDate.getFullYear();
	document.getElementById(varTarget).value = varOutput;
	
}

function OnCopy(varCopy, varNotCopy)
{
	if(confirm(unescape(varLangCopyEntry)))
	{
		Submitform(varCopy);
	}
	else
	{
		Submitform(varNotCopy);
	}
}

function OnConfirm(action)
{
	if(document.adminForm.boxchecked.value == 0)
	{
		alert(unescape(varLangChooseAnEntry));
	}
	else
	{
		if(confirm(unescape(varLangDeleteEntry)))
		{
			CheckAdminForm(action);
		}
	}
}

function CheckAdminForm(action)
{
	if(document.adminForm.boxchecked.value == 0)
	{
		alert(unescape(varLangChooseAnEntry));
	}
	else
	{
		Submitform(action);
	}
}

function CheckCommentIsSet(action)
{
	if(document.adminForm.commentTextActualJob.value != "")
	{
		Submitform(action);
	}
	else
	{
		alert(unescape(varLangComment));
	}
}

function IsChecked(isitchecked)
{
	if (isitchecked == true){
		document.adminForm.boxchecked.value++;
	}
	else {
		document.adminForm.boxchecked.value--;
	}
}
function Submitform(action)
{
	if (action) 
	{
		try
		{
		document.adminForm.action.value=action;
		}
		catch(Exception)
		{
			alert(action);
		}
		try
		{
			document.adminForm.item.value = GetRadioButtonID(document.adminForm.id);
		}
		catch(Exception)
		{
			
		}
	}
	else
	{
		
	}
	if (typeof document.adminForm.onsubmit == "function") 
	{
		document.adminForm.onsubmit();
	}
	document.adminForm.submit();
}

function GetRadioButtonID(radioObj) {
	if (!radioObj) {
		return '';
	}
	var n = radioObj.length;
	if (n == undefined) {
		if (radioObj.checked) {
			return radioObj.value;
		} else {
			return '';
		}
	}
	for (var i = 0; i < n; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return '';
}
function ListItemTask( id, task ) 
{

    var f = document.adminForm;
    cb = eval( 'f.' + id );
    if (cb) {
        for (i = 0; true; i++) {
            cbx = eval('f.cb'+i);
            if (!cbx) break;
            cbx.checked = false;
        } // for
        cb.checked = true;
        f.boxchecked.value = 1;
        Submitform(task);
    }
    return false;
}

function OnConfirmListItemTask(id, task)
{
	if(confirm(unescape(varLangDeleteEntry)))
	{
		ListItemTask(id, task);
	}
	
}

function SetAccess(type, moduleID)
{
	if(type == "full")
	{
		document.getElementById("write-"+moduleID).checked = document.getElementById("full-"+moduleID).checked;
		document.getElementById("read-"+moduleID).checked = document.getElementById("full-"+moduleID).checked;
		document.getElementById("special-"+moduleID).checked = document.getElementById("full-"+moduleID).checked;
		document.getElementById("delete-"+moduleID).checked = document.getElementById("full-"+moduleID).checked;
	}
	else if(type == "write")
	{
		if(!document.getElementById("write-"+moduleID).checked)
		{
			document.getElementById("special-"+moduleID).checked = document.getElementById("write-"+moduleID).checked;
			document.getElementById("delete-"+moduleID).checked = document.getElementById("write-"+moduleID).checked;
			document.getElementById("full-"+moduleID).checked = document.getElementById("write-"+moduleID).checked;
		}
		else
		{
			document.getElementById("read-"+moduleID).checked = document.getElementById("write-"+moduleID).checked;
		}
	}
	else if(type == "delete")
	{
		if(!document.getElementById("delete-"+moduleID).checked)
		{
			document.getElementById("full-"+moduleID).checked = document.getElementById("delete-"+moduleID).checked;
			document.getElementById("special-"+moduleID).checked = document.getElementById("delete-"+moduleID).checked;
		}
		else
		{
			document.getElementById("read-"+moduleID).checked = document.getElementById("delete-"+moduleID).checked;
			document.getElementById("write-"+moduleID).checked = document.getElementById("delete-"+moduleID).checked;
		}
	}
	else if(type == "read")
	{
		if(!document.getElementById("read-"+moduleID).checked)
		{
			document.getElementById("write-"+moduleID).checked = document.getElementById("read-"+moduleID).checked;
			document.getElementById("read-"+moduleID).checked = document.getElementById("read-"+moduleID).checked;
			document.getElementById("special-"+moduleID).checked = document.getElementById("read-"+moduleID).checked;
			document.getElementById("delete-"+moduleID).checked = document.getElementById("read-"+moduleID).checked;
			document.getElementById("full-"+moduleID).checked = document.getElementById("read-"+moduleID).checked;
		}
	}
	
	var varWrite = document.getElementById("write-"+moduleID).checked;
	var varRead = document.getElementById("read-"+moduleID).checked;
	var varSpecial = document.getElementById("special-"+moduleID).checked;
	var varDelete = document.getElementById("delete-"+moduleID).checked;
	
	var varGroup = document.adminForm.usergroup.value;
	var varLink = "./permission.php?type=module&moduleid="+moduleID+"&groupid="+varGroup+"&write="+varWrite+"&read="+varRead+"&delete="+varDelete+"&special="+varSpecial;
	
	LoadWithJava(varLink, "permissionResult");
}

function ToggleTree(node) 
{
	var nextDIV = node.nextSibling;
	var node2 = document.getElementById(node.childNodes.item(1).id);
	while(nextDIV.nodeName != "DIV") 
	{
		nextDIV = nextDIV.nextSibling;
	}
	

	if (nextDIV.style.display == 'none') 
	{
		if (node2.childNodes.length > 0) 
		{
			if (node2.childNodes.item(1).nodeName == "IMG") 
			{
				node2.childNodes.item(1).src = GetImgDirectory(node2.childNodes.item(1).src) + "minus.gif";
			}
		}
		
		nextDIV.style.display = 'block';

	}
	else 
	{
		if (node2.childNodes.length > 0) 
		{
			if (node2.childNodes.item(1).nodeName == "IMG") 
			{

  				node2.childNodes.item(1).src = GetImgDirectory(node2.childNodes.item(1).src) + "plus.gif";

			}

		}
		nextDIV.style.display = 'none';
	}

}

function ToggleAll(state)
{
	var divCount = Number(document.getElementById("divCount").value);
	
	if(divCount == 0)
		return;
	
	for(var i = 0; i < divCount; i++)
	{
		var div = document.getElementById("divTree"+i);
		var node = document.getElementById("divImg"+i);
		
		if(state == true)
		{
			
			if (node.childNodes.length > 0) 
			{
				if (node.childNodes.item(1).nodeName == "IMG") 
				{
					node.childNodes.item(1).src = GetImgDirectory(node.childNodes.item(1).src) + "minus.gif";
				}
			}

			div.style.display = 'block';
		}
		else
		{
			if (node.childNodes.length > 0) 
			{
				if (node.childNodes.item(1).nodeName == "IMG") 
				{

	  				node.childNodes.item(1).src = GetImgDirectory(node.childNodes.item(1).src) + "plus.gif";

				}

			}

			div.style.display = 'none';
		}
		
	}
}

function GetImgDirectory(source) 
{
    return source.substring(0, source.lastIndexOf('/') + 1);
}

function LoadJob(jobID)
{
	Load("getData.php?s=paintJob&id="+jobID, "actualJob");
}
function StopRunningJob(jobID)
{
	if(confirm(unescape(varLangStopJob)))
	{
		var varValue = document.getElementById("stopCommentText").value;
		varValue = varValue.replace(/&/g, "%*%");
		varValue = varValue.replace(/\n/g, "<br />");
		
		AjaxPost("getData.php", "s=stopJob&id="+jobID+"&comment="+varValue, "actualJob");
		window.setTimeout("Redirect('index.php?s=online')", 1500);
	}
}

function StartLastJob()
{
	var varValue = document.getElementById("commentLastJobText").value;
	
	if(varValue == "")
	{
		alert(varLangComment);
		return;
	}
	
	varValue = varValue.replace(/&/g, "%*%");
	AjaxPost("getData.php", "s=startLastJob&comment="+varValue, "lastJobResult");
	window.setTimeout("Redirect('index.php?s=online')", 1500);
}

function PauseRunningJob(jobID, pauseID)
{
	Load("getData.php?s=pauseJob&id="+jobID+"&pauseid="+pauseID, "actualJob");
	window.setTimeout("Redirect('index.php?s=online')", 1500);
}
function CommentRunningJob(jobID, get, set, result)
{
	var varValue = document.getElementById(get).value;
	varValue = varValue.replace(/&/g, "%*%");
	try
	{
		document.getElementById(set).value = varValue;
	}
	catch(Exception)
	{
		document.getElementById("stopCommentText").value = varValue;
		
		varValue = varValue.replace(/\n/g, "<br />");
		AjaxPost("getData.php", "s=commentJob&id="+jobID+"&comment="+varValue, result);
		return;
	}
	document.getElementById("stopCommentText").value = varValue;
	
	varValue = varValue.replace(/\n/g, "<br />");
	AjaxPost("getData.php", "s=commentJob&id="+jobID+"&comment="+varValue, result);

}

function OpenMenu(varDiv)
{
	var div = document.getElementById(varDiv);
	
	if (div.style.display == 'none') 
	{
		document.getElementById(varDiv).style.display = "block";
	}
	else
	{
		document.getElementById(varDiv).style.display = "none";
	}
}

function OpenHelpMenu(id, site)
{
	var winLeft = (screen.width - 640) / 2;
	var winTop = (screen.height - 480) / 2;
	var winProps = 'height=480,width=640,top='+winTop+',left='+winLeft+',scrollbars=1,resizable';
	win = window.open("help.php?id="+id+"&s="+site, varLangHelp, winProps);
	win.window.focus();
}

function EditHelpPage(id)
{
	document.getElementById("text").style.display = 'block';
	document.getElementById("help").style.display = 'none';
	CKEDITOR.replace("ckeditor");
}
function SaveHelpPage(id)
{
	var varValue = CKEDITOR.instances.ckeditor.getData(); 
	varValue = varValue.replace(/&/g, "%*%");
	
	document.getElementById("text").style.display = 'none';
	document.getElementById("help").style.display = 'block';

	AjaxPost("getData.php", "s=help&id="+id+"&text="+varValue, "help");
	CKEDITOR.remove("ckeditor");
}
